package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.SProductEnquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.SProductEnquiryQuery;
import com.by.query.SupplierProductEnquiryQuery;
import com.by.service.SProductEnquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Ye QS
 * @version 0.1
 * @className ProductEnquiryController
 * @description
 * @date 2024/9/26 14:17
 * @since jdk11
 */
@RestController
@RequestMapping("/v1")
@Api(tags = "产品询价")
public class SProductEnquiryController extends BaseController {
    @Autowired
    SProductEnquiryService sProductEnquiryService;

    @ApiOperation("供应商询价")
    @PostMapping("/product/enquiry/supplier")
    public ResultBean querySupplier(@RequestBody SupplierProductEnquiryQuery query) {
        PageBean pageBean = sProductEnquiryService.querySupplierProductEnquiry(query);
        return success("供应商询价", pageBean);
    }

    @ApiOperation("保存询价")
    @PostMapping("/product/enquiry")
    public ResultBean save(@RequestBody SProductEnquiry enquiry) {
        int rs = sProductEnquiryService.save(enquiry);
        return saveResult(rs);
    }

    @ApiOperation("查询询价")
    @PostMapping("/product/enquiry/query")
    public ResultBean query(@RequestBody SProductEnquiryQuery query) {
        Map<String, Object> map = BeanUtil.beanToMap(query);
        PageBean bean = sProductEnquiryService.query(map);
        return success("产品询价列表", bean);
    }
    @ApiOperation("报价详情")
    @GetMapping("/product/enquiry")
    public ResultBean queryDetail(@RequestParam(required = true) int id){
        Map map=sProductEnquiryService.queryDetail(id);
        return success("报价详情",map);
    }
}
